package com.example.demo.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;

/**
 * 用户实体类.
 * @author zmf
 */
@Entity
@Table(name = "CS_SM_USER_D")
@DynamicUpdate
@DynamicInsert
@ApiModel("用户信息")
public class User implements Serializable {
    private static final long serialVersionUID = 8585154981959921384L;

	@Id
	@Column(name = "CS_SM_USER_ID")
	/*@SequenceGenerator(name = "USER_SEQ", sequenceName = "S_AAS_USER", allocationSize = 1)
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "USER_SEQ")*/
    @ApiModelProperty("用户ID")
    private Long userId;

    @ApiModelProperty("登录名")
	@Column(name = "LOGIN_NAME", unique = true, nullable = false, length = 60)
    @NotBlank
    @Length(max = 60)
	private String loginName;

    @ApiModelProperty("姓名")
	@Column(name = "ALIAS", length = 100)
    @Length(max = 100)
	private String alias;

    @ApiModelProperty("密码(使用MD5加密)")
	@Column(name = "PASSWORD", nullable = false, length = 50,updatable = false)
    @Length(max = 50)
	private String password;

    @ApiModelProperty("用户状态")
	@Column(name = "STATUS", nullable = false)
    @NotNull
	private Integer status;

    @ApiModelProperty("用户类型")
	@Column(name = "USER_TYPE", nullable = false)
    private Integer userType = 2;

    @ApiModelProperty("邮箱")
	@Column(name = "EMAIL",length = 100)
    @Length(max = 100)
	private String eMail;

    @ApiModelProperty("电话号码")
	@Column(name = "TELEPHONE",length = 50)
    @NotBlank
    @Length(max = 50)
	private String telephone;

    @ApiModelProperty("描述信息")
	@Column(name = "DESCRIPTION")
    @Length(max = 255)
	private String description;

    @ApiModelProperty("创建人ID")
	@Column(name = "CREATE_USER_ID", nullable = false,updatable = false)
	private Long createUserId;

    @ApiModelProperty("插入时间")
	@Column(name = "CREATE_TIME", nullable = false,updatable = false)
	private Date createTime;

    @ApiModelProperty("更新时间")
    @Column(name = "UPDATE_TIME")
	private Date updateTime;

    @ApiModelProperty("默认密码")
    @Column(name = "DEFAULT_PWD")
    private String defaultPwd;

    @ApiModelProperty("办公电话")
	@Column(name = "OFFICE_PHONE",length = 50)
    @Length(max = 50)
	private String officePhone;

    @ApiModelProperty("区域ID")
    @Column(name = "REGION_ID",nullable = false)
    @NotNull
    private Long  regionId;

    @ApiModelProperty("组织机构ID")
    @Column(name = "ORG_ID",nullable = false)
    private Long orgId;

    @ApiModelProperty("是否合作伙伴")
	@Column(name = "IS_PARTNER")
    private Integer isPartner = 1;

    @ApiModelProperty("性别")
	@Column(name = "SEX")
	private Integer sex = 1;

    @ApiModelProperty("身份证号码")
	@Column(name = "PID",length = 20)
    @Length(max = 20)
	private String pid;

    @ApiModelProperty("拼音")
	@Column(name = "PINGYIN",length = 50)
    @Length(max = 50)
	private String pingyin;

    @ApiModelProperty("生日")
	@Column(name = "BIRTHDAY",length = 20)
    @Length(max = 20)
	private String birthday;

//    @ApiModelProperty("排序字段")
//	@Column(name = "ORDER_INDEX")
//	private Long orderIndex = 1L;

    @ApiModelProperty("密码更新时间")
	@Column(name = "PWD_UPDATE_TIME")
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date passwordUpdateDate;

    @ApiModelProperty("领导标识")
	@Column(name = "IS_LEADER")
    private Integer isLeader = 0;

//    @ApiModelProperty("服务管理员标识")
//	@Column(name = "IS_SERVICE_MANAGER")
//    private Integer isServiceManager = 0;

//    @ApiModelProperty("预留字段1")
//	@Column(name = "ARG1")
//	private Long arg1;
//
//    @ApiModelProperty("预留字段2")
//	@Column(name = "ARG2")
//	private Long arg2;
//
//    @ApiModelProperty("预留字段3")
//	@Column(name = "ARG3")
//    @Length(max = 255)
//	private String arg3;
//
//    @ApiModelProperty("预留字段4")
//	@Column(name = "ARG4")
//    @Length(max = 255)
//	private String arg4;

    @ApiModelProperty("全量区域ID")
    @Column(name = "FULL_REGION")
    @Length(max = 255)
    private String fullRegion;

    @ApiModelProperty("全量区域名称")
    @Column(name = "FULL_REGION_NAME")
    @Length(max = 255)
    private String fullRegionName;

    @ApiModelProperty("工号")
    @Column(name = "JOB_NUMBER")
    private String jobNumber;

    @ApiModelProperty("创建人")
    @Column(name = "CREATE_USER_NAME")
    private String createUserName;

    @ApiModelProperty("修改人")
    @Column(name = "UPDATE_USER_NAME")
    private String updateUserName;

    @ApiModelProperty("补充字段1 - 单位")
    @Column(name = "arg1")
    private String arg1;

    @ApiModelProperty("补充字段2 - 岗位")
    @Column(name = "arg2")
    private String arg2;

    @ApiModelProperty("补充字段3")
    @Column(name = "arg3")
    private String arg3;

    @ApiModelProperty("补充字段4")
    @Column(name = "arg4")
    private String arg4;

	public void setPassword(String password) {
		this.password = password;
		//当密码为不空时【不是编辑状态】,做set值操作
		if(StringUtils.isNotBlank(this.password)){
            this.passwordUpdateDate = new Date();
//            this.passwordUpdateDate = LocalDateTime.now();
        }
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
            return true;
        }
		if (obj == null) {
            return false;
        }
		if (getClass() != obj.getClass()) {
            return false;
        }
		User other = (User) obj;
		if (userId == null) {
            return other.userId == null;
		} else if (!userId.equals(other.userId)) {
            return false;
        }
		return true;
	}

	public String getRealRegion() {
		if (StringUtils.isNotBlank(this.fullRegion)) {
			String[] regionArray = this.fullRegion.split("/");
			return regionArray[regionArray.length - 1];
		} else {
			return this.regionId.toString();
		}
	}

    public String getJobNumber() {
        return jobNumber;
    }

    public void setJobNumber(String jobNumber) {
        this.jobNumber = jobNumber;
    }

    public String getCreateUserName() {
        return createUserName;
    }

    public void setCreateUserName(String createUserName) {
        this.createUserName = createUserName;
    }

    public String getUpdateUserName() {
        return updateUserName;
    }

    public void setUpdateUserName(String updateUserName) {
        this.updateUserName = updateUserName;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getAlias() {
        return alias;
    }

    public void setAlias(String alias) {
        this.alias = alias;
    }

    public String getPassword() {
        return password;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getUserType() {
        return userType;
    }

    public void setUserType(Integer userType) {
        this.userType = userType;
    }

    public String geteMail() {
        return eMail;
    }

    public void seteMail(String eMail) {
        this.eMail = eMail;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Long getCreateUserId() {
        return createUserId;
    }

    public void setCreateUserId(Long createUserId) {
        this.createUserId = createUserId;
    }

    public String getDefaultPwd() {
        return defaultPwd;
    }

    public void setDefaultPwd(String defaultPwd) {
        this.defaultPwd = defaultPwd;
    }
//    public Date getInsertTime() {
//        return insertTime;
//    }
//
//    public void setInsertTime(Date insertTime) {
//        this.insertTime = insertTime;
//    }


    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getOfficePhone() {
        return officePhone;
    }

    public void setOfficePhone(String officePhone) {
        this.officePhone = officePhone;
    }

    public Long getRegionId() {
        return regionId;
    }

    public void setRegionId(Long regionId) {
        this.regionId = regionId;
    }

    public Long getOrgId() {
        return orgId;
    }

    public void setOrgId(Long orgId) {
        this.orgId = orgId;
    }

    public Integer getIsPartner() {
        return isPartner;
    }

    public void setIsPartner(Integer isPartner) {
        this.isPartner = isPartner;
    }

    public Integer getSex() {
        return sex;
    }

    public void setSex(Integer sex) {
        this.sex = sex;
    }

    public String getPid() {
        return pid;
    }

    public void setPid(String pid) {
        this.pid = pid;
    }

    public String getPingyin() {
        return pingyin;
    }

    public void setPingyin(String pingyin) {
        this.pingyin = pingyin;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

//    public Long getOrderIndex() {
//        return orderIndex;
//    }
//
//    public void setOrderIndex(Long orderIndex) {
//        this.orderIndex = orderIndex;
//    }

    public Date getPasswordUpdateDate() {
        return passwordUpdateDate;
    }

    public void setPasswordUpdateDate(Date passwordUpdateDate) {
        this.passwordUpdateDate = passwordUpdateDate;
    }

//    public LocalDateTime getPasswordUpdateDate() {
//        return passwordUpdateDate;
//    }
//
//    public void setPasswordUpdateDate(LocalDateTime passwordUpdateDate) {
//        this.passwordUpdateDate = passwordUpdateDate;
//    }

    public Integer getIsLeader() {
        return isLeader;
    }

    public void setIsLeader(Integer isLeader) {
        this.isLeader = isLeader;
    }

//    public Integer getIsServiceManager() {
//        return isServiceManager;
//    }
//
//    public void setIsServiceManager(Integer isServiceManager) {
//        this.isServiceManager = isServiceManager;
//    }


    public String getArg1() {
        return arg1;
    }

    public void setArg1(String arg1) {
        this.arg1 = arg1;
    }

    public String getArg2() {
        return arg2;
    }

    public void setArg2(String arg2) {
        this.arg2 = arg2;
    }

    public String getArg3() {
        return arg3;
    }

    public void setArg3(String arg3) {
        this.arg3 = arg3;
    }

    public String getArg4() {
        return arg4;
    }

    public void setArg4(String arg4) {
        this.arg4 = arg4;
    }

    public String getFullRegion() {
        return fullRegion;
    }

    public void setFullRegion(String fullRegion) {
        this.fullRegion = fullRegion;
    }

    public String getFullRegionName() {
        return fullRegionName;
    }

    public void setFullRegionName(String fullRegionName) {
        this.fullRegionName = fullRegionName;
    }

    @Override
    public String toString() {
        return "User{" +
            "userId=" + userId +
            ", loginName='" + loginName + '\'' +
            ", alias='" + alias + '\'' +
            ", password='" + password + '\'' +
            ", status=" + status +
            ", userType=" + userType +
            ", eMail='" + eMail + '\'' +
            ", telephone='" + telephone + '\'' +
            ", description='" + description + '\'' +
            ", createUserId=" + createUserId +
//            ", insertTime=" + insertTime +
            ", updateTime=" + updateTime +
            ", officePhone='" + officePhone + '\'' +
            ", regionId=" + regionId +
            ", orgId=" + orgId +
            ", isPartner=" + isPartner +
            ", sex=" + sex +
            ", pid='" + pid + '\'' +
            ", pingyin='" + pingyin + '\'' +
            ", birthday='" + birthday + '\'' +
//            ", orderIndex=" + orderIndex +
            ", passwordUpdateDate=" + passwordUpdateDate +
            ", isLeader=" + isLeader +
//            ", isServiceManager=" + isServiceManager +
            ", arg1='" + arg1 + '\'' +
            ", arg2='" + arg2 + '\'' +
            ", arg3='" + arg3 + '\'' +
            ", arg4='" + arg4 + '\'' +
            ", fullRegion='" + fullRegion + '\'' +
            ", fullRegionName='" + fullRegionName + '\'' +
            '}';
    }
}
